﻿using System.Web.Mvc;
using System.Web.Routing;

namespace Ams.Mvc.Bootstrap
{
    public class BootstrapHelper
    {
        public BootstrapHelper(ViewContext viewContext, IViewDataContainer viewDataContainer)
            : this(viewContext, viewDataContainer, RouteTable.Routes)
        {
            ViewContext = viewContext;
            ViewDataContainer = viewDataContainer;
        }

        public BootstrapHelper(ViewContext viewContext, IViewDataContainer viewDataContainer, RouteCollection routeCollection)
        {
            ViewContext = viewContext;
            ViewDataContainer = viewDataContainer;
            ViewData = new ViewDataDictionary(viewDataContainer.ViewData);
            RouteCollection = routeCollection;
        }

        public IViewDataContainer ViewDataContainer { get; set; }
        public ViewDataDictionary ViewData { get; private set; }
        public ViewContext ViewContext { get; private set; }
        public RouteCollection RouteCollection { get; private set; }

        public HtmlHelper Html
        {
            get { return new HtmlHelper(ViewContext, ViewDataContainer); }
        }

        public BootstrapMvcForm Form { get; set; }
    }

    public class BootstrapHelper<TModel> : BootstrapHelper
    {
        public BootstrapHelper(ViewContext viewContext, IViewDataContainer container)
            : this(viewContext, container, RouteTable.Routes)
        {
        }
        
        public BootstrapHelper(ViewContext viewContext, IViewDataContainer container, RouteCollection routeCollection)
            : base(viewContext, container, routeCollection)
        {
            ViewData = new ViewDataDictionary<TModel>(container.ViewData);
        }

        public new ViewDataDictionary<TModel> ViewData { get; private set; }

        public new HtmlHelper<TModel> Html
        {
            get { return new HtmlHelper<TModel>(ViewContext, ViewDataContainer); }
        }
    }
}
